home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / dict / skip_test.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  1KB  |  58 lines

  1. #include <LEDA/impl/skiplist.h>
  2. #include <LEDA/stream.h>
  3.  
  4. main(int argc, char** argv)
  5. {
  6.   string_istream args(argc-1,argv+1);
  7.  
  8.   float p0 = 0.20;
  9.   float p1 = 0.60;
  10.  
  11.   int   N  = 10000;
  12.  
  13.   args >> p0 >> p1 >> N;
  14.  
  15.   cout << string("# keys = %d     p0 = %f   p1 = %f\n",N,p0,p1);
  16.   newline;
  17.  
  18.   GenPtr* RAND = new GenPtr[N];
  19.  
  20.   init_random(12345);
  21.  
  22.   for(int i=0; i<N; i++) RAND[i] = (GenPtr)random(0,MAXINT-1);
  23.  
  24.   float T0 = used_time();
  25.   float T  = used_time();
  26.  
  27.  
  28.   newline;
  29.   cout << "               insert    lookup    delete     total\n";
  30.   newline;
  31.  
  32.   for(float prob = p0; prob < p1; prob += 0.01)
  33.   { 
  34.     skiplist skip(prob);
  35.  
  36.     cout << string("p = %4.2f   ",prob);
  37.     cout.flush();
  38.  
  39.     for(i=0; i<N; i++)  skip.insert(RAND[i],0);
  40.     cout << string("%10.2f",used_time(T));
  41.     cout.flush();
  42.  
  43.  
  44.     for(i=0; i<N; i++)  skip.lookup(RAND[i]);
  45.     cout << string("%10.2f",used_time(T));
  46.     cout.flush();
  47.  
  48.     for(i=0; i<N; i++)  skip.del(RAND[i]);
  49.     cout << string("%10.2f",used_time(T));
  50.  
  51.     cout << string("%10.2f",used_time(T0));
  52.     newline;
  53.  
  54.    }
  55.  
  56.   return 0;
  57. }
  58.